<template>
  <div class="scale-box">
    <slot></slot>
  </div>
</template>
    <script setup>
import { ref, onMounted, defineProps } from "vue";
const width = ref(null), //设计宽度
  height = ref(null), //设计高度
  scale = ref(null);

const props = defineProps({
  width: {
    type: String || Number,
    default: "1920",
  },
  height: {
    type: String || Number,
    default: "1080",
  },
});
const width1 = ref("");
const height1 = ref("");
const init = () => {
  setScale();
  window.addEventListener("resize", setScale);
};
const setScale = () => {
  let ww = window.innerWidth / props.width;
  let wh = window.innerHeight / props.height;
  width1.value = props.width + "px";
  height1.value = props.height + "px";
  scale.value = ww < wh ? ww : wh;
};

init();
</script>
    <style>
.scale-box {
  width: v-bind("width1");
  height: v-bind("height1");

  transform: scale(v-bind(scale)) translate(-50%, -50%);
  transform-origin: 0 0;
  position: absolute;
  left: 50%;
  top: 50%;
  transition: 0.3s;
}
</style>